<?php

/*
 * // +----------------------------------------------------------------------
 * // | erp
 * // +----------------------------------------------------------------------
 * // | Copyright (c) 2006~2020 erp All rights reserved.
 * // +----------------------------------------------------------------------
 * // | Licensed ( LICENSE-1.0.0 )
 * // +----------------------------------------------------------------------
 * // | Author: yxx <1365831278@qq.com>
 * // +----------------------------------------------------------------------
 */

namespace App\Admin\Metrics;

use App\Models\ProjectAgreement;
use Dcat\Admin\Admin;
use Dcat\Admin\Widgets\Metrics\Bar;
use Illuminate\Http\Request;

class Agreement extends Bar
{
    /**
     * 初始化卡片内容
     */
    protected function init()
    {
        parent::init();

        $color = Admin::color();

        // 卡片内容宽度
        $this->contentWidth(5, 7);
        // 标题
        $this->title('劳务协议统计');
        // 设置下拉选项
        // $this->dropdown([
        //     '7' => 'Last 7 Days',
        //     '28' => 'Last 28 Days',
        //     '30' => 'Last Month',
        //     '365' => 'Last Year',
        // ]);
        // 设置图表颜色
        $this->chartColors([
            $color->orange(),
            $color->green(),
            $color->red(),
            $color->blue(),
        ]);
    }

    /**
     * 处理请求
     *
     * @param Request $request
     *
     * @return mixed|void
     */
    public function handle(Request $request)
    {
        // 卡片内容
        $this->withContent();

        $agreement = ProjectAgreement::all();

        // 协议总数
        $total = $agreement->count() ?? 0;
        // 审核通过协议数
        $adopt = $agreement->where('status', 1)->count() ?? 0;

        // 审核驳回协议数
        $reject = $agreement->where('status', -1)->count() ?? 0;
        // 支付完成协议数
        $payment = $agreement->where('pay_status', 2)->count() ?? 0;

        // 图表数据
        $this->withChart([
            [
                'name' => '',
                'data' => [$total, $adopt, $reject, $payment],
            ],

        ]);
    }

    /**
     * 设置图表数据.
     *
     * @param array $data
     *
     * @return $this
     */
    public function withChart(array $data)
    {
        return $this->chart([
            'series' => $data,
        ]);
    }

    /**
     * 设置卡片内容.
     *
     * @param string $title
     * @param string $value
     * @param string $style
     *
     * @return $this
     */
    public function withContent($style = 'success')
    {
        // 根据选项显示
        $minHeight = '183px';

        return $this->content(
            <<<HTML
<div class="d-flex p-1 flex-column justify-content-between" style="padding-top: 0;width: 100%;height: 100%;min-height: {$minHeight}">
    <div class="text-left">
      <ul>
  <li><span class="color-box orange"></span> 协议总数</li>
  <li><span class="color-box green"></span> 审核通过协议数</li>
  <li><span class="color-box red"></span> 审核驳回协议数</li>
  <li><span class="color-box blue"></span> 支付完成协议数</li>
</ul>
    </div>
</div>
<style>
  ul {

    list-style-type: none; /* 移除列表项前的默认项目符号 */
  }
  li {
    margin-bottom: 5px; /* 列表项之间的间隔 */
  }
  .color-key {
    color: #333; /* 颜色说明文字的颜色 */
    font-weight: bold; /* 颜色说明文字的字体加粗 */
  }
  .color-box {
    display: inline-block; /* 将div设置为行内块元素 */
    width: 15px; /* 颜色块的宽度 */
    height: 15px; /* 颜色块的高度 */
    margin-right: 5px; /* 颜色块和文字之间的间隔 */
    vertical-align: middle; /* 颜色块垂直居中 */
  }
  /* 定义各种颜色的颜色块 */
  .red { background-color: #ea5455; }
  .orange { background-color: #dda451; }
  .green { background-color: #21b978; }
  .blue { background-color: #3085d6; }
</style>
HTML
        );
    }
}
